import log from '@dfeidao/atom-nodejs/logger/log';
import { IncomingHttpHeaders } from 'http';
import query from '@dfeidao/atom-nodejs/db/query';
import { systemid,productid } from '../../atom/config';

interface Message {
	filter: {
		data_v:string,
		question_bank_type:string,
		topic_type:string,
		topic:string,
	}
	// cookie: {
	// 	uk: string;
	// 	[key: string]: string
	// };
	// urls: {
	// 	base: string;
	// 	origin: string;
	// 	url: string;
	// };
	// query: {};
	// params: {};
	// headers: {};
	// captcha: string;
}
// 1. 查<试题库> question_bank 表取字段：

// "试题编号/question_no"、==对应"试题编号"、

// "题目/topic"、==对应"题目名称"、

// "题目类型/topic_type"、==对应"题目类型"、

// "题库类型/question_bank_type"、==对应"题库类型"、


export default async function atom(message: Message, action_id: string, session_id: string, headers: IncomingHttpHeaders){
	const { prepare, exec } = query(action_id, session_id, systemid);
		prepare('question_bank', ['question_no', 'topic', 'topic_type', 'question_bank_type'],
		{ productid,topic: { $like: ("%" + message.filter.topic + "%")},
		topic_type: { $like: ("%" + message.filter.topic_type + "%")},
		question_bank_type: { $like: ("%" + message.filter.question_bank_type + "%")}
	}, 20, 1, [], ['question_no']);
		prepare('question_bank', ['question_no', 'topic', 'topic_type', 'question_bank_type'],
		{ productid ,topic: { $like: ("%" + message.filter.topic + "%")},
		topic_type: { $like: ("%" + message.filter.topic_type + "%")},
		question_bank_type: { $like: ("%" + message.filter.question_bank_type + "%")}}, 20, 1, ['question_no'], []);
		prepare('question_bank', ['question_no', 'topic', 'topic_type', 'question_bank_type'],
		{ productid,topic: { $like: ("%" + message.filter.topic + "%")},
		topic_type: { $like: ("%" + message.filter.topic_type + "%")},
		question_bank_type: { $like: ("%" + message.filter.question_bank_type + "%")}}, 20, 1, ['topic'], []);
		prepare('question_bank', ['question_no', 'topic', 'topic_type', 'question_bank_type'],
		{ productid,topic: { $like: ("%" + message.filter.topic + "%")},
		topic_type: { $like: ("%" + message.filter.topic_type + "%")},
		question_bank_type: { $like: ("%" + message.filter.question_bank_type + "%")}}, 20, 1, [], ['topic']);
		prepare('question_bank', ['question_no', 'topic', 'topic_type', 'question_bank_type'],
		{ productid,topic: { $like: ("%" + message.filter.topic + "%")},
		topic_type: { $like: ("%" + message.filter.topic_type + "%")},
		question_bank_type: { $like: ("%" + message.filter.question_bank_type + "%")}}, 20, 1, ['topic_type'], []);
		prepare('question_bank', ['question_no', 'topic', 'topic_type', 'question_bank_type'],
		{ productid,topic: { $like: ("%" + message.filter.topic + "%")},
		topic_type: { $like: ("%" + message.filter.topic_type + "%")},
		question_bank_type: { $like: ("%" + message.filter.question_bank_type + "%")}}, 20, 1, [], ['topic_type']);
		prepare('question_bank', ['question_no', 'topic', 'topic_type', 'question_bank_type'],
		{ productid,topic: { $like: ("%" + message.filter.topic + "%")},
		topic_type: { $like: ("%" + message.filter.topic_type + "%")},
		question_bank_type: { $like: ("%" + message.filter.question_bank_type + "%")}}, 20, 1, ['question_bank_type'], []);
		prepare('question_bank', ['question_no', 'topic', 'topic_type', 'question_bank_type'],
		{ productid,topic: { $like: ("%" + message.filter.topic + "%")},
		topic_type: { $like: ("%" + message.filter.topic_type + "%")},
		question_bank_type: { $like: ("%" + message.filter.question_bank_type + "%")}}, 20, 1, [], ['question_bank_type']);
	const [d1,d2,d3,d4,d5,d6,d7,d8] = await exec();
	return { d1,d2,d3,d4,d5,d6,d7,d8 };
}
